import { defHttp } from '/@/utils/http/axios';
import { ErrorMessageMode } from '/#/axios';

enum Api {
  // 获取租户列表
  getTenantList = '/tenant/page/list',
  // 创建租户
  createTenant = '/tenant/create',
  // 更新租户
  updateTenant = '/tenant/update',
  // 删除租户
  tenant = '/tenant',
  // 获取全部租户
  getTenantAllList = '/tenant/all/list',
  // 获取租户应用列表
  getTenantApplicationList = '/tenant/relation/page/list',
  // 创建租户应用
  createTenantApplication = '/tenant/relation/create',
  // 同步租户应用
  synTenantApplication = '/tenant/relation/syn',
}

export function getTenantList(data, mode: ErrorMessageMode = 'modal') {
  const url = Api.getTenantList;
  return defHttp.post(
    { url: url, data },
    {
      errorMessageMode: mode,
    }
  );
}

export function createTenant(data, mode: ErrorMessageMode = 'modal') {
  const url = Api.createTenant;
  return defHttp.post(
    { url: url, data },
    {
      errorMessageMode: mode,
    }
  );
}

export function updateTenant(data, mode: ErrorMessageMode = 'modal') {
  const url = Api.updateTenant;
  return defHttp.put(
    { url: url, data },
    {
      errorMessageMode: mode,
    }
  );
}

export function deleteTenant(id: string, mode: ErrorMessageMode = 'modal') {
  const url = `${Api.tenant}/${id}`;
  return defHttp.delete(
    { url: url },
    {
      errorMessageMode: mode,
    }
  );
}

export function getTenantAllList(mode: ErrorMessageMode = 'modal') {
  const url = Api.getTenantAllList;
  return defHttp.get(
    { url: url },
    {
      errorMessageMode: mode,
    }
  );
}

export function getTenantApplicationList(data, mode: ErrorMessageMode = 'modal') {
  const url = Api.getTenantApplicationList;
  return defHttp.post(
    { url: url, data },
    {
      errorMessageMode: mode,
    }
  );
}
export function createTenantApplication(data, mode: ErrorMessageMode = 'modal') {
  const url = Api.createTenantApplication;
  return defHttp.post(
    { url: url, data },
    {
      errorMessageMode: mode,
    }
  );
}

export function synTenantApplication(data, mode: ErrorMessageMode = 'modal') {
  const url = Api.synTenantApplication;
  return defHttp.put(
    { url: url, data },
    {
      errorMessageMode: mode,
    }
  );
}
